﻿/*
=======================================================
    CheckWireropeDetail【在用绳检测详情】
=======================================================
*/

namespace Services
{
    public interface ICheckWireropeDetailMapping : IMapping<CheckWireropeDetail, CheckWireropeDetailModel, CheckWireropeDetailFilterModel>
    { }

    public class CheckWireropeDetailMapping : AutoCheckWireropeDetailMapping, ICheckWireropeDetailMapping
    {
        private readonly ICheckWireropeDetailDataMapping _ICheckWireropeDetailDataMapping;
        private readonly ICheckWireropeDetailPositionMapping _ICheckWireropeDetailPositionMapping;

        public CheckWireropeDetailMapping(ICurrentUser currentUser, ICheckWireropeDetailDataMapping iCheckWireropeDetailDataMapping, ICheckWireropeDetailPositionMapping iCheckWireropeDetailPositionMapping)
            : base(currentUser)
        {
            _ICheckWireropeDetailDataMapping = iCheckWireropeDetailDataMapping;
            _ICheckWireropeDetailPositionMapping = iCheckWireropeDetailPositionMapping;
        }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailModel Entity2Model(CheckWireropeDetail entity)
        {
            if (entity == null)
            {
                return null;
            }

            CheckWireropeDetailModel model = base.Entity2Model(entity);


            /***************************************** 下面处理自定义转换 *****************************************/

            if (entity.CheckWireropeDetailDatas.IsNotEmpty() && entity.CheckWireropeDetailDatas.Count > 0)
            {
                model.CheckWireropeDetailDataModels = _ICheckWireropeDetailDataMapping.Entity2Model(entity.CheckWireropeDetailDatas);
            }

            if (entity.CheckWireropeDetailPositions.IsNotEmpty() && entity.CheckWireropeDetailPositions.Count > 0)
            {
                model.CheckWireropeDetailPositionModels = _ICheckWireropeDetailPositionMapping.Entity2Model(entity.CheckWireropeDetailPositions);
            }

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override CheckWireropeDetail Model2Entity(CheckWireropeDetailModel model)
        {
            CheckWireropeDetail entity = base.Model2Entity(model);


            /***************************************** 下面处理自定义转换 *****************************************/

            if (model.CheckWireropeDetailDataModels.IsNotEmpty() && model.CheckWireropeDetailDataModels.Count > 0)
            {
                entity.CheckWireropeDetailDatas = _ICheckWireropeDetailDataMapping.Model2Entity(model.CheckWireropeDetailDataModels);
            }

            if (model.CheckWireropeDetailPositionModels.IsNotEmpty() && model.CheckWireropeDetailPositionModels.Count > 0)
            {
                entity.CheckWireropeDetailPositions = _ICheckWireropeDetailPositionMapping.Model2Entity(model.CheckWireropeDetailPositionModels);
            }

            return entity;
        }
        #endregion

        #region 读数据(集合)
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entities">Entity对象</param>
        /// <returns></returns>
        public override List<CheckWireropeDetailModel> Entity2Model(IEnumerable<CheckWireropeDetail> entities)
        {
            return entities.Select(x => Entity2Model(x)).ToList();
        }
        #endregion

        #region 写数据(集合)
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="models">ViewModel对象</param>
        /// <returns></returns>
        public override List<CheckWireropeDetail> Model2Entity(IEnumerable<CheckWireropeDetailModel> models)
        {
            return models.Select(x => Model2Entity(x)).ToList();
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<CheckWireropeDetail> FilterModel2Where(CheckWireropeDetailFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //SearchInput
            if (!string.IsNullOrEmpty(filterModel._SearchInput))
            { }

            ////捻距内断丝数
            //if (filterModel._DsCnt.HasValue)
            //{
            //    where = where.And(x => x.DsCnt == filterModel._DsCnt.Value);
            //}

            ////LA
            //if (filterModel._DsLa.HasValue)
            //{
            //    where = where.And(x => x.DsLa == filterModel._DsLa.Value);
            //}

            ////位置
            //if (filterModel._ZjPosition.HasValue)
            //{
            //    where = where.And(x => x.ZjPosition == filterModel._ZjPosition.Value);
            //}

            ////DIA
            //if (filterModel._ZjDia.HasValue)
            //{
            //    where = where.And(x => x.ZjDia == filterModel._ZjDia.Value);
            //}

            ////位置
            //if (filterModel._JsjmPosition.HasValue)
            //{
            //    where = where.And(x => x.JsjmPosition == filterModel._JsjmPosition.Value);
            //}

            ////LMA
            //if (filterModel._JsjmLma.HasValue)
            //{
            //    where = where.And(x => x.JsjmLma == filterModel._JsjmLma.Value);
            //}

            ////腐蚀情况
            //if (!string.IsNullOrEmpty(filterModel._OthFuShi))
            //{
            //    where = where.And(x => x.OthFuShi.Contains(filterModel._OthFuShi));
            //    //where = where.And(x => x.OthFuShi == filterModel._OthFuShi);
            //}

            ////磨损情况
            //if (!string.IsNullOrEmpty(filterModel._OthMoSun))
            //{
            //    where = where.And(x => x.OthMoSun.Contains(filterModel._OthMoSun));
            //    //where = where.And(x => x.OthMoSun == filterModel._OthMoSun);
            //}

            ////其他损伤
            //if (!string.IsNullOrEmpty(filterModel._OthQiTa))
            //{
            //    where = where.And(x => x.OthQiTa.Contains(filterModel._OthQiTa));
            //    //where = where.And(x => x.OthQiTa == filterModel._OthQiTa);
            //}

            ////综合判定
            //if (!string.IsNullOrEmpty(filterModel._OthZongHe))
            //{
            //    where = where.And(x => x.OthZongHe.Contains(filterModel._OthZongHe));
            //    //where = where.And(x => x.OthZongHe == filterModel._OthZongHe);
            //}


            return where;
        }
        #endregion
    }
}
